package cn.lcsjsxy.yxc.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet(value = "/servletA")
public class ServletA extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //创建cookie
        Cookie cookie1 = new Cookie("nameA", "valueA");

        //设置cookie的持久化时间
        cookie1.setMaxAge(60*5);

        //设置cookie的提交路径
        cookie1.setPath("/servletB");

        Cookie cookie2 = new Cookie("nameB", "valueB");
        cookie2.setMaxAge(60*5);

        //将cookie放入response对象
        resp.addCookie(cookie1);
        resp.addCookie(cookie2);
    }
}
